const SFCScriptBlock = require('@vue/compiler-sfc')
const {getExposeNode} = require("./relNode");

/**
 * 解析 expose
 * @param {SFCScriptBlock} scriptBlock vue解析后的Script块
 */
function relExpose(scriptBlock) {
    const exposeMap = {}
    const exposeNode = getExposeNode(scriptBlock)
    if (!exposeNode) return null
    const arguments = exposeNode.arguments
    if (arguments && arguments.length > 0) {
        const properties = arguments[0].properties
        if (properties && properties.length > 0) {
            for (let property of properties) {
                const propInfo = {
                    value: '',
                    desc: ''
                }
                // todo 解析函数和变量
                propInfo.value = property.value.name
                if (property.leadingComments && property.leadingComments.length > 0) {
                    propInfo.desc = property.leadingComments[0].value
                }
                exposeMap[property.key.name] = propInfo
            }
        }
    }
    return exposeMap
}

exports.relExpose = relExpose
